<?php

    require_once('../framework/msc-load.php');

    if(isset($_GET['action']) && $_GET['action'] == 'getHotels'){
        global $db;
    
        $query = 'SELECT * FROM HOTELS';
        $result = $db->query($query); 

        $hotels = array();

        if($result):
            while ($row = $result->fetch_assoc()):
                $facilities = unserialize($row['Facilities']);
                $photos = unserialize($row['Photos']);
                array_push($hotels, array( "hotelID" => $row['ID'], "hotelName" => $row['Name'], "hotelStars" => $row['Stars'], "hotelAddress" => $row['Address'], "hotelCity" => $row['City'], "hotelCountry" => $row['Country'], "hotelZIP" => $row['PostalCode'], "hotelPhone" => $row['Phone'], "hotelDetails" => $row['Details'], "hotelEmail" => $row['Email'], "hotelWebsite" => $row['Website'], "hotelPhotos" => $photos, "hotelFacilities" => $row['Facilities'], "hotelFacilities" => $facilities, "hotelCoords" => $row['Coordinates'], "isFeatured" => $row['isFeatured']));
            endwhile;
        endif;

        echo json_encode($hotels);
    }
    
?>